from pymongo import MongoClient

from scenedetect import VideoManager
from scenedetect import SceneManager
from scenedetect.detectors import ContentDetector
client = MongoClient(port=27017)
db=client['tiktok']
threshold=30.0

collist=['makeitvogue','LGBTQHistory','wip']
for col in collist:
    for item in db[col]:
        video_manager = VideoManager(['E:\\Tiktok\\Hashtag\\'+col+'\\' + item['_id'] + '.mp4'])
        scene_manager = SceneManager()
        scene_manager.add_detector(ContentDetector(threshold=threshold))
        base_timecode = video_manager.get_base_timecode()
        video_manager.set_downscale_factor()
        video_manager.start()
        scene_manager.detect_scenes(frame_source=video_manager)
        scenes = scene_manager.get_scene_list(base_timecode)
        db[col].update_one({'_id': item['_id']}, {'$set': {'video_feature.editing': {'num_scenes':len(scenes)}}})


